package com.tianzheng.rzzl.base

import com.basic.library.bean.DataResult
import com.basic.library.bean.UserInfo
import com.basic.library.httpmanager.task.RHttpManager
import com.basic.library.utils.AESUtils
import com.basic.library.utils.DateUtils
import com.basic.library.utils.JsonUtils
import com.tianzheng.rzzl.R
import java.util.*

/**
 * @author yj
 * @description
 */
class PushText {
}

//java 友盟推送生成签名
fun send() {
    val appkey = PushHelper.getString(R.string._AppKey)
    val app_master_secret = "x62ziujl4fwxa1hlqz4ead3xbz7mdmqd"
    val timestamp = System.currentTimeMillis()
    val method = "POST"
    val url = "http://msg.umeng.com/api/send"
    val params =
        "{\"appkey\":\"$appkey\",\"timestamp\":$timestamp,\"description\":\"测试\",\"payload\":{\"display_type\":\"notification\",\"body\":{\"ticker\":\"标题\",\"text\":\"内容\",\"title\":\"标题\",\"after_open\":\"go_app\",\"play_sound\":true}},\"type\":\"customizedcast\",\"alias_type\":\"PushId\",\"alias\":\"83e36916-2779-4e96-b3c3-fb414fa734a0\",\"mipush\":true,\"mi_activity\":\"com.tz.tzoa.MfrMessageActivity\",\"policy\":{\"expire_time\":\"2021-11-25 18:45:34\"}}"
    val map = JsonUtils.fromJson(params, PushInfo1::class.java).apply {
        type = "broadcast"
        policy.expire_time = DateUtils.dateToStrLong(Calendar.getInstance().apply {
            add(Calendar.DATE, 1)
        }.time)
        payload.display_type = "notification"  // // 必填，消息类型: notification(通知)、message(消息)
    }
//    println(JsonUtils.toJson(map))
    val sStr = "$method$url${JsonUtils.toJson(map)}$app_master_secret"
    println(sStr)
    val sign = AESUtils.encoder(sStr)
//    println(sign)
    val mde = "$url?sign=$sign"
    println(mde)
    RHttpManager.obj().postbodyAsync(null, mde, map,
        object : RHttpManager.ResultCallback<DataResult<UserInfo>>() {
            override fun onResponse(response: DataResult<UserInfo>) {

            }
        })
}

data class PushInfo1(
    var alias: String,
    var alias_type: String,
    var appkey: String,
    var description: String,
    var mi_activity: String,
    var mipush: Boolean,
    var payload: Payload,
    var policy: Policy,
    var timestamp: Long,
    var type: String
)

data class Payload(
    var body: Body,
    var display_type: String
)

data class Body(
    var after_open: String,
    var play_sound: Boolean,
    var text: String,
    var ticker: String,
    var title: String
)

data class Policy(
    var expire_time: String
)